package birdry.ui.components
{
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.EventDispatcher;	

	public class UIComponent 	{
		
		/**
		 * 그래픽 리소스
		 */
		protected var _view : DisplayObject;
		
		/**
		 * 활성화 상태를 구분 합니다.
		 */ 
		protected var _enabled : Boolean;
		
		public function UIComponent(view : DisplayObject) 		{
			_view = view;
			if (_view is Sprite)			{
				_view["tabEnabled"] = false;
				_view["tabChildren"] = false;
			}
		}
		
		// ----------------------------------------------------------------------------
		// Public Method
		// ----------------------------------------------------------------------------
		public function addEventListener(type:String, listener:Function): void	{
			_view.addEventListener(type, listener);
		}
		
		public function removeEventListener(type:String, listener:Function): void	{
			_view.removeEventListener(type, listener);
		}
		
		protected function dispatchEvent( event: Event ): void	{
			_view.dispatchEvent( event );
		}
		
		public function setLocation(x : Number, y : Number) : void 		{
			if (_view == null) return;
			_view.x = x;
			_view.y = y;
		}
		
		public function setSize(width : Number, height : Number) : void 		{
			if (this.view == null) return;
			this.view.width = width;
			this.view.height = height;
		}
		
		public function setScale(rate : Number) : void		{
			view.scaleX = rate;
			view.scaleY = rate;
		}		
		
		public function destroy() : void 		{			
			if (_view.parent != null) _view.parent.removeChild(_view);					
			view = null;
		}
		
		public function setVisible(visible : Boolean) : void		{
			_view.visible = visible;
		}		
		
		// ----------------------------------------------------------------------------
		// Getter & Setter
		// ----------------------------------------------------------------------------		
		
		public function get view() : DisplayObject 		{
			return _view;
		}
		
		public function set view(view : DisplayObject) : void 		{
			_view = view;
		}
		
		public function get enabled() : Boolean 		{
			return _enabled;
		}
		
		public function set enabled(enabled : Boolean) : void 		{
			_enabled = enabled;
		}

	} // end class
} // end package